package com.wyix.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public ModelAndView handleException(Exception e) {
        logger.error("发生未预期的错误", e);
        ModelAndView modelAndView = new ModelAndView("error");
        modelAndView.addObject("errorMessage", "发生未预期的错误，请稍后再试。");
        return modelAndView;
    }
}
